package com.huatai.exchange.send;

import com.faneui.common.exception.BusinessException;
import com.huatai.exchange.dal.model.ExcCommunication;
import com.huatai.exchange.dal.model.ExcCustomer;
import com.huatai.exchange.facade.CommunicationContents;
import com.huatai.exchange.facade.Contents;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service("fileMailSendService")
public class FileMailSendServiceImpl extends AbstractFileSendServiceImpl implements FileSendService {

    @Override
    public void sendMessage( ExcCustomer customer, Map<String, Object> resvMap) throws BusinessException {
        boolean b = resvMap.get("fileNames") == null || StringUtils.isBlank(resvMap.get("fileNames").toString());
        String fileNames = b ? null : resvMap.get("fileNames").toString();
        String filePaths = b ? null : resvMap.get("filePaths").toString();
        String toMails = customer.getToMails();
        String mailTitle = (String) resvMap.get(CommunicationContents.MAIL_TITLE);
        String mailContent = (String) resvMap.get(CommunicationContents.MAIL_CONTENT);
        if (StringUtils.isBlank(fullInfo)) {
            fullInfo = dictService.getKeyValue(Contents.SERVER_INFO);
        }
        mailContent = mailContent + "\n\n\n\n\n\n\n\n\n" + fullInfo;
        communicationService.sendMail(mailTitle, mailContent, toMails, fileNames, filePaths);
    }
}
